cmake_minimum_required(VERSION 3.8)
project(topo_nav)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(PCL REQUIRED COMPONENTS common io)
find_package(pcl_conversions REQUIRED)
find_package(interface REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML_CPP REQUIRED yaml-cpp)

# Generate custom service
rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/NavMsg.srv"
)

# Build the main node
add_executable(topo_nav_node src/main.cpp)

include_directories(
  ${PCL_INCLUDE_DIRS}
)

target_include_directories(topo_nav_node PRIVATE ${YAML_CPP_INCLUDE_DIRS})
target_link_libraries(topo_nav_node ${YAML_CPP_LIBRARIES})

ament_target_dependencies(topo_nav_node
  rclcpp
  geometry_msgs
  nav_msgs
  sensor_msgs
  std_srvs
  tf2
  tf2_ros
  pcl_conversions
  interface
)

target_link_libraries(topo_nav_node
  yaml-cpp
  ${PCL_LIBRARIES}
)

# Link against generated interfaces
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(topo_nav_node "${cpp_typesupport_target}")

# Install targets
install(TARGETS
  topo_nav_node
  DESTINATION lib/${PROJECT_NAME}
)

# Install directories
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/
)

# Install configuration file directory (if any)
install(DIRECTORY
  config
  DESTINATION share/${PROJECT_NAME}/
)

install(DIRECTORY
  rviz
  DESTINATION share/${PROJECT_NAME}/
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
